<extend name="Base:common" />                                                                                                    
<block name="body">

<link rel="stylesheet" type="text/css" href="__CSS__/go/Comm.css"/>
<link rel="stylesheet" type="text/css" href="__CSS__/go/CartList.css"/>
<link rel="stylesheet" type="text/css" href="__CSS__/go/cart.css" />
<script src="__JS__/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="__Public__/plugins/plugins/jquery.cookie.js"></script>
<script src="__PUBLIC__/plugins/layer/layer.min.js"></script>
<script type="text/javascript">
    var ThinkPHP = window.Think = {
        "ROOT"   : "__ROOT__",
        "APP"    : "__APP__",
        "PUBLIC" : "__PUBLIC__",
        "DEEP"   : "{:C('URL_PATHINFO_DEPR')}",
        "MODEL"  : ["{:C('URL_MODEL')}", "{:C('URL_CASE_INSENSITIVE')}", "{:C('URL_HTML_SUFFIX')}"],
        "VAR"    : ["{:C('VAR_MODULE')}", "{:C('VAR_CONTROLLER')}", "{:C('VAR_ACTION')}"]
    }
</script>
<script src="__PUBLIC__/js/think.js"></script>
<div class="container">
        <!--S cart-->
    <div id="shopCartBox">
        <div class="show_content">
        
<div class="shop_payment">
        <ul class="payment">
           <li class="first_step orange_Tech">第一步：提交订单</li>
            <li class="arrow_3"></li>
            <li class="secend_step">第二步：在线支付</li>
            <li class="arrow_2"></li>
            <li class="third_step">第三步：支付成功 等待揭晓</li>
            <li class="arrow_2"></li>
            <li class="fourth_step">第四步：揭晓获得者</li>
            <!-- <li class="arrow_2"></li>
            <li class="fifth_step">第五步：晒单奖励</li> -->
        </ul>
</div>      
            
        <div class="shop-cart-box">
    <div class="shop-cart-box-hd"><h6 class="title">我的云购清单</h6></div>
    <div class="shop-cart-box-bd">
        <dl class="shop-cart-goods">
            <input type="hidden" id="hiddenCartList" value='{$jsonCartList}'>
            <dt class="clearfix">
                <span class="col col-0"><input type="checkbox" class="checkAll" style="margin-top:5px;"/></span>
                <span class="col col-1" style="width: 50.5%;text-indent:80px;">商品</span>
                <span class="col col-2" style="width: 10%;">价值</span>
                <span class="col col-2" style="width: 10%;">云购价</span>
                <span class="col col-3" style="width: 13%;">数量</span>
                <span class="col col-4" style="width: 8%;">剩余</span>
                <span class="col col-5" style="width: 5%;">操作</span>
            </dt>
            <volist name="cartList" id="vo">
             <dd class="item" id="shoplist{$vo['id']}">
                <div class="item-row">
                    <div class="col col-0" style=""><input type="checkbox" value="{$vo['id']}" style="margin-top:5px;margin-left:20px;"/></div>
                    <div class="col col-1">
                        <div class="g-pic"><a href="{:U('Home/Yungo/index',array('to'=>4,'gid'=>$vo['id']))}" target="_blank"><img alt="{$vo['title']}" src="__ROOT__/{$vo['thumb']}" width="120" height="120"></a></div>
                        <div class="g-info">
                            <div class="g-name"><a href="{:U('Home/Yungo/index',array('to'=>4,'gid'=>$vo['id']))}" target="_blank">{$vo['title']}</a><br /><p class="tips"></p></div>
                        </div>
                    </div>
                    <div class="col col-2">{$vo['money']}元</div>
                     <div class="col col-2">{$vo['yunjiage']}元</div>
                    <div class="col col-3" style="width:170px;">
                            <div class="change-goods-num num">
                                <a href="javascript:;" class="J_minus cart_num_add" style="text-decoration: none" val="{$vo['id']}"><i class="iconfont">-</i></a>
                                <input type="type" val="{$vo['id']}" onkeyup="value=value.replace(/\D/g,'')" value="{$vo['num']}" class="goods-num"/>
                                <a href="javascript:;" class="J_plus cart_num_j" style="text-decoration: none" val="{$vo['id']}"><i class="iconfont">+</i></a>
                            </div>
                    </div>
                    <div class="col col-4"><em>{$vo['shenyu']}</em>人次</div>
                    <div class="col col-5"><a  href="javascript:;" onclick="delcart({$vo['id']})" <i class="iconfont">删除</i></a></div>
                </div>
            </dd>
            </volist>
                        
            <dd class="item clearfix item-d">
                <div class="col col-1">
                    <div class="g-pic" style="padding-left:0;"><span class="icon-activity icon-activity-my">免邮</span></div>
                    <div class="g-info">
                        <div class="activity-info clearfix">云购全场免邮费</div>
                    </div>
                </div>
                <div class="col col-2"></div>
                <div class="col col-3"></div>
                <div class="col col-4"></div>
                <div class="col col-5"></div>
            </dd>
            
        </dl>
    </div>
    
</div>

</div>
</div>
</div>
<div class="cart_box">
    <a href="javascript:;" class="delete_selete" style="margin-left:20px;font-size:14px;">删除选中商品</a>
    <div class="shop-cart-total" style="float:right;padding-right:10px;"><p class="total-price">商品总计：<span><strong id="MoneyCount">{$MoneyCount}</strong>元</span></p></div>
</div>
<div style="width:1200px;margin:0 auto;height:30px;">
<a href="{:U('Home/Yungo/index')}" style="padding:10px 20px;background:#DF057D;float:left;border-radius:5px;color:#fff;font-size:16px;text-decoration: none">返回云购</a>
<a style="width: 200px; background: #DF057D; color: rgb(255, 255, 255); display: block; height: 44px; text-align: center; line-height: 44px;float:right;font-size:18px;text-decoration: none;border-radius:5px;" href="javascript:;" class="btn btn-primary btn-next" id="but_ok">提交订单</a>
</div>
<div class="recommend_goods">推荐产品</div>
<div class="recommend">
    <volist name="posGoods" id="vo">
    <dl>
        <dt><a href="#" title="{$vo['title']}" target="_blank"><img src="__ROOT__/{$vo['thumb']}" alt="{$vo['title']}"/></a></dt>
        <dd class="goods_name"><p><a href="#" title="{$vo['title']}" target="_blank">{$vo['title']}</a></p></dd>
        <dd>总需：{$vo['zongrenshu']}人次</dd>
    </dl>
    </volist>

    </div>

<script type="text/javascript">
$('.checkAll').click(function(){
    var checkAll = $('.shop-cart-goods dd input[type=checkbox]');
    checkAll.each(function(index){
        checkAll.eq(index).attr('checked') ? checkAll.eq(index).removeAttr('checked','false') : checkAll.eq(index).attr('checked','true');
    });
});
$('.delete_selete').click(function(){
    var obj = $('.shop-cart-goods dd input[type=checkbox]');
    var ids = '';
    obj.each(function(index){
        if(obj.eq(index).is(':checked')){
            ids += obj.eq(index).val()+'|';
        }
    });
    if(ids == ''){
        layer.msg('请选择至少一件商品',{
            shade : 0.3,
        });
        return false;
    }
    var arr = ids.split('|');
    $.post(Think.U('Home/Yungo/delSelete'),{ids:arr},function(data,textStatus){
        if(data['status'] == 1){
            window.location.reload();
        }else{
            layer.msg('删除失败',{
                shade : 0.3,
            });
            return false;
        }   
    })
}); 

var info=$.parseJSON($('#hiddenCartList').val());
var numberadd=$(".J_plus");
var numbersub=$(".J_minus");
var xiaoji=$(".xj");
var num=$(".goods-num");
var message=$(".tips");
var MoneyCount=$("#MoneyCount");

$(function(){
    $("#but_ok").click(function(){
        var countmoney=parseInt(MoneyCount.text());
        if(countmoney > 0){
            //$.cookie('Cartlist',$.toJSON(info),{expires:30,path:'/'});
            location.href = "{:U('Home/Yungo/index',array('to'=>2))}";
        }else{
            alert("购物车为空!");
        }
    });
});
function UpdataMoney(shopid,number,zindex){
        var number = parseInt(number);
        info['MoneyCount']=info['MoneyCount']-info[shopid]['yunjiage']*info[shopid]['num']+info[shopid]['yunjiage']*number;
        info[shopid]['num']=number;
        var xjmoney=xiaoji.eq(zindex+1);
            xjmoney.text(info[shopid]['yunjiage']*number+'.00');
            MoneyCount.text(info['MoneyCount']+'.00');
        $.ajax({
            type : 'POST',
            url : '?/member/cart/change',
            data : {goods_id:shopid,number:number},
            dataType : 'json',
            success : function(res){
                
            },
        });
}

//删除单个商品
function delcart(id){
    //info['MoneyCount'] = info['MoneyCount']-info[id]['yunjiage']*info[id]['num'];
    //$("#shoplist"+id).hide();
    //$("#MoneyCount").text(info['MoneyCount']+".00");
    //delete info[id];
    //$.cookie('Cartlist','',{path:'/'});
    //$.cookie('Cartlist',$.toJSON(info),{expires:30,path:'/'});
    layer.open({
    title: '系统提示',
    content: '确认删除商品吗？',
    icon: 3,
    btn: ['确认', '取消'],
    shadeClose: false,
    yes: function(){
        layer.open({content: '你点了确认', time: 1});
        $.ajax({
            type : 'POST',
            url : '/index.php?m=Go&c=Ajax&a=delCartItem&gid='+id,
            dataType : 'json',
            success : function(data){
                if(data['code'] == 1){
                    layer.open({content: '删除失败', time: 1});
                }else{
                    info['MoneyCount'] = info['MoneyCount']-info[id]['yunjiage']*info[id]['num'];
                    $("#shoplist"+id).hide();
                    $("#MoneyCount").text(info['MoneyCount']+".00");
                    //window.location.reload();
                }
            },
        });
    }, no: function(){}
    });
}
num.keyup(function(){
    var shopid=$(this).attr("val");
    var zindex=num.index(this);
    if($(this).val() > info[shopid]['shenyu']){
        message.eq(zindex).text("购买次数不能超过"+info[shopid]['shenyu']+"人次");
        $(this).val(info[shopid]['shenyu']);
        UpdataMoney(shopid,$(this).val(),zindex);
        return;
    }
    if($(this).val()<1){
        message.eq(zindex).text("购买次数不能少于1人次");
        $(this).val(1);
        UpdataMoney(shopid,$(this).val(),zindex);
        return;
    }
    UpdataMoney(shopid,$(this).val(),zindex);
});
numberadd.click(function(){
    var id=$(this).attr('val');
    var zindex=numberadd.index(this);
    var thisnum=num.eq(zindex);
    if(info[id]['num'] >= info[id]['shenyu']){
        message.eq(zindex).text("购买次数不能超过"+info[id]['shenyu']+"人次");
        return;
    }
    $.ajax({
        type : 'POST',
        url : '/index.php/Home/Yungo/changeNum',
        data : {gid:id,num:1},
        dataType : 'json',
        success : function(data){
            if(data['status'] == -1){
                message.eq(zindex).text("增加失败,购买次数不能超过"+info[id]['shenyu']+"人次");
                return;
            }else{
                var number=info[id]['num']+1;
                thisnum.val(number);
                UpdataMoney(id,number,zindex);
            }
        },
    });
});
numbersub.click(function(){
    var id=$(this).attr('val');
    var zindex=numbersub.index(this);
    var thisnum=num.eq(zindex);
    if(info[id]['num'] <=1){
        message.eq(zindex).text("购买次数不能少于1人次");
        return;
    }
    $.ajax({
        type : 'POST',
        url : '/index.php/Home/Yungo/changeNum',
        data : {gid:id,num:-1},
        dataType : 'json',
        success : function(data){
            if(data['status'] == -1){
                message.eq(zindex).text("减少失败,购买次数不能少于1人次");
                return;
            }else{
                var number=info[id]['num']-1;
                thisnum.val(number);
                UpdataMoney(id,number,zindex);
            }
        },
    });
});

</script>
</block>